//
//  QuestionAnswerFiltrateView.m
//  HappyMother
//
//  Created by 易东 on 2017/10/25.
//  Copyright © 2017年 东哥. All rights reserved.
//

#import "QuestionAnswerFiltrateView.h"

@implementation QuestionAnswerFiltrateView
-(void)awakeFromNib
{
    [super awakeFromNib];
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        if ([obj isKindOfClass:NSClassFromString(@"UIButton")]) {
            
            UIButton *btn = (UIButton *)obj;
            btn.clipsToBounds = YES;
            btn.layer.borderWidth = 1;
            btn.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
            btn.layer.cornerRadius = 3;
        }
    }];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    
    _touchView.userInteractionEnabled = YES;
    
    [_touchView addGestureRecognizer:tap];
    
}
-(void)tap:(UITapGestureRecognizer *)gr{
    if (_cancelBlock) {
        _cancelBlock(@"");
    }
}
#pragma mark - 选择标签
- (IBAction)select:(id)sender {
    
    UIButton *btn = (UIButton *)sender;
    
    if (btn.currentTitleColor == [UIColor purpleColor]) {
        
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
    }else{
        
        [btn setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
        
        if (btn.tag==11||btn.tag==12||btn.tag==13||btn.tag==14) {
            //全部设置为黑色
            UIButton *allBtn = [self viewWithTag:10];
            [allBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            
        }
        
        if (btn.tag==10) {
            
            [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj isKindOfClass:NSClassFromString(@"UIButton")]) {
                    
                    UIButton *btn = (UIButton *)obj;
                    
                    if (btn.tag==11||btn.tag==12||btn.tag==13||btn.tag==14) {
                       [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    }
                    
                }
            }];
        }
        
    }
    
    
}

- (IBAction)right:(id)sender {
    
    if (_ensureBlock) {
        _ensureBlock(sender);
    }
}
@end
